package com.yuanmeng.common.core.enums;

import com.yuanmeng.common.core.exception.ServiceException;
import lombok.Getter;

/**
 * 用户类型
 * 
 * @author 安然
 */
@Getter
public enum UserTypeEnum {
    PERSONAL("PERSONAL", "个人"),

    INDIVIDUAL("INDIVIDUAL", "个体"),

    BUSINESS("BUSINESS", "企业");

    private String code;
    private String message;

    UserTypeEnum(String code, String message)
    {
        this.code = code;
        this.message = message;
    }

    public static void validateUserType(String userType) {
        int num = 0;
        for(UserTypeEnum ENUM : UserTypeEnum.values()) {
            if(ENUM.code.equals(userType)) {
                num ++;
            }
        }
        if(num == 0) {
            throw new ServiceException("请求参数非法：userType");
        }
    }

    public static String codeQueryValue(String userType) {
        for(UserTypeEnum ENUM : UserTypeEnum.values()) {
            if(ENUM.code.equals(userType)) {
                return ENUM.getMessage();
            }
        }
        return "";
    }

    public static String valueQueryCode(String userType) {
        for(UserTypeEnum ENUM : UserTypeEnum.values()) {
            if(ENUM.message.equals(userType)) {
                return ENUM.getCode();
            }
        }
        return "";
    }
}
